package com.nny.Demo530;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class TestConnection {
    private  static  final  String URL ="jbbc:mysql://localhost:3306/usersDb";
    private  static final  String DB_username="root";
    private  static final  String DB_password="123456";

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
       Class.forName("com.mysql.jdbc.Driver");
        Connection conn= DriverManager.getConnection(URL,DB_username,DB_password);
        String sql="insert into users(DB_username,DB_password,number,age) values(?,?,?,?)";
        PreparedStatement pstm = conn.prepareStatement(sql);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username= scanner.next();
        System.out.println("请输入编号");
        String number= scanner.next();
        System.out.println("请输入密码");
        String password= scanner.next();
        System.out.println("请输入年龄");
        int age= scanner.nextInt();
        pstm.setString(1,username);
        pstm.setString(2,password);
        pstm.setString(3,number);
        pstm.setInt(4,age);
        int i=pstm.executeUpdate();
        if(i>0){
            System.out.println("成功");
        }
        else{
            System.out.println("失败");
        }
    }
}
